<%@ taglib prefix="p" uri="/WEB-INF/tld/privilege.tld" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%     
	String path = request.getContextPath();     
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";     
%> 
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <title>部门列表</title>
  <base href="<%=basePath%>"/>
  <link rel="stylesheet" type="text/css" href="css/common.css" />
  <link rel="stylesheet" type="text/css" href="js/tablesorter/css/theme.green.css" />
  <link type="text/css" href="js/mcdropdown/css/jquery.mcdropdown.css" rel="stylesheet" media="all" />
  <script type="text/javascript" src="js/mcdropdown/lib/jquery-1.7.1.min.js"></script>
  <script type="text/javascript" src="js/jquery.form.js"></script>
  <script type="text/javascript" src="js/tablesorter/jquery.tablesorter.min.js"></script>
  <script type="text/javascript" src="js/tablesorter/jquery.tablesorter.widgets.js"></script>
  <script type="text/javascript" src="js/mcdropdown/lib/jquery.mcdropdown.js"></script>
  <script type="text/javascript" src="js/mcdropdown/lib/jquery.bgiframe.js"></script>
  <style type="text/css">
	fieldset,table,tr,td {margin:0; padding:0;}
	form td {padding:0 5px 0 10px;}
	form label {font-weight:bold;}
	#content{margin:5px 0px;}
	#btnbar{margin:5px 0px;}
  </style>

  <script type="text/javascript">
	$(document).ready(function() { 
		$.ajaxSetup ({ cache:false, async:false });
       	$("#deptTable").tablesorter({theme:'green', widgets:['zebra', "resizable"]});
       	$("#pNo").mcDropdown("#categorymenu",{ dropShadow: false, targetColumnSize: 1, lineHeight:30, allowParentSelect:true});
       	
       	$("#btn_pageUp").click(function(){
			var curPage = $("#curPage").val();
			$("#curPage").val(parseInt(curPage) - 1);
			$("#deptForm").submit();
       	});
       	
       	$("#btn_pageDown").click(function(){
       		var curPage = $("#curPage").val();
			$("#curPage").val(parseInt(curPage) + 1);
			$("#deptForm").submit();
       	});

        $("#btn_insert").click(function(){
            var queryString = $("#deptForm").formSerialize();
            queryString = encodeURIComponent(queryString);
            location.href = "<%=basePath%>system/dept/insert.do?qs=" + queryString;
        });
        
        $("#btn_search").click(function(){
            $("#curPage").val(1);
            return true;
        });
        
        $("#btn_clear").click(function(){
        	var resetPNo = $("#pNo").mcDropdown();
        	resetPNo.setValue('');
        	$("#deptNo").val('');
            $("#deptName").val('');
            return true;
        });

        $("#btn_change").click(function(){
            var page = parseInt($("#selectPage").val());
            var curPage = parseInt($("#curPage").val());
            if(curPage == page) return;
            $("#curPage").val(parseInt(page));
            $("#deptForm").submit();
        });
	});

	function edit(deptNo) {
        var queryString = $("#deptForm").formSerialize();
        queryString = encodeURIComponent(queryString);
        location.href = "<%=basePath%>system/dept/edit.do?deptNo=" + deptNo + "&qs=" + queryString;
	}
	
	function del(deptNo) {
		if(confirm("确定删除该对象？") != 1) return;
		$.post("system/dept/delete.do", {deptNo:deptNo}, function(data) {
			var result = $.parseJSON(data);
			if(result.code == 1) {
				alert("删除成功!");
				$("#btn_search").click();
			} else {
				alert(result.message);
			}
		});
	}
  </script>
 </head>

 <body>
  <div>
    <fieldset>
      <legend>查询条件：</legend>
      <form id="deptForm" method="post" action="system/dept/list.do">
        <table>
          <tr>
            <td><label for="enname">部门编号：</label></td>
            <td><input type="text" name="deptNo" id="deptNo"  value="${deptNo}" style="width:150px;" /></td>
            <td><label for="alias">名称：</label></td>
            <td><input type="text" name="deptName" id="deptName" value="${deptName}" style="width:150px;" /></td>
            <td><label for="parentId">上级部门：</label></td>
            <td style="width:250px;">
               <input type="text" name="pNo" id="pNo" value ="${pNo}" defaultValue="${pNo}"/>
               <ul id="categorymenu" class="mcdropdown_menu">
			        <c:forEach items="${treeList}" var="tree" varStatus="status">
			            ${tree}
			        </c:forEach>
		       </ul>  	
            </td>              
               <td><input type="submit" id="btn_search" name="btn_search" value="查询" style="width:80px;" /></td>
               <td><input type="button" name="btn_clear" id="btn_clear" value="重置" style="width:80px;" /></td> 
          </tr>
        </table>
        <input type="hidden" name="curPage" id="curPage" value="${curPage}" />
      </form>
    </fieldset>
  </div>
  
  <div id = "content">
  	<table id="deptTable" class="tablesorter">
	  <thead> 
	    <tr> 
          <th>部门编号</th> 
	      <th>部门名称</th>
	      <th>上级部门</th>
	      <th>地址</th>
          <th>地区</th> 
	      <th>描述</th> 
	      <th class="sorter-false">操作</th>
 	    </tr> 
	  </thead>
	  <tbody>
	  
	   <c:forEach items="${deptList}" var="dept" varStatus="status">
		  <tr>
		  	  <td>${dept.deptNo}</td>
		  	  <td>${dept.deptName}</td>
		  	  <td>${dept.pDeptName}</td>
		  	  <td>${dept.address}</td>
	          <td>${dept.area}</td>
		  	  <td>${dept.describe}</td>
		  	  <td>
		  	   <p:chkPri actionUrl="system/dept/view.do">	 <a href="system/dept/view.do?deptNo=${dept.deptNo}">查看</a></p:chkPri>
		  	   <p:chkPri actionUrl="system/dept/edit.do">	 <a href=# onclick="javascript:edit('${dept.deptNo}'); return false;">修改</a></p:chkPri>
		  	   <p:chkPri actionUrl="system/dept/delete.do">	 <a href=# onclick="javascript:del('${dept.deptNo}'); return false;">删除</a></p:chkPri>
		  	  </td>
	     </tr>         
	   </c:forEach>
	  </tbody>
  	</table>
  </div>

  <div id = "btnbar">
      <div style="float:left;">
        <p:chkPri actionUrl="system/dept/insert.do"><input id="btn_insert" type="button" value="新增" /></p:chkPri>
      </div>
      <div style="text-align:right;">
        <c:if test="${curPage <= 1}"><input type="button" disabled="disabled" id="btn_pageUp" value="上一页"/></c:if>
        <c:if test="${curPage > 1}"><input type="button" id="btn_pageUp" value="上一页"/></c:if>
        <c:if test="${curPage >= totalPage}"><input type="button" id="btn_pageDown" disabled="disabled" value="下一页"/></c:if>
        <c:if test="${curPage < totalPage}"><input type="button" id="btn_pageDown" value="下一页"/></c:if>
                     共${totalPage}页/共${totalRecords}条
        <select id="selectPage" style="width: auto;">
            <c:forEach var="i" begin="1" end="${totalPage}">
                <option id="${i}" <c:if test="${i == curPage}">selected="selected"</c:if>>${i}</option>
            </c:forEach>
        </select>
        <input id="btn_change" type="button" value="转至" />
      </div>
  </div>
 </body>
</html>

